﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AjaxData_Leader_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string act=Request["action"];
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "clb_save":
                    var clb_bl = new Com.Ooohd.Bll.Leader.ZS_Celebrity();
                    var clb = clb_bl.CreateModel();
                    string id = Request["rcid"];
                    if (!string.IsNullOrEmpty(id)) {
                        clb = clb_bl.GetSingle(int.Parse(id));
                    }
                    clb.Name = Request["clb_name"];
                    clb.VisitedDate = DateTime.Parse(Request["vist_date"]);
                    clb.Profile=Request["profile"];
                    clb.Img = Request["previewImg"];
                    clb.Detail=Request["content"];
                    if (!string.IsNullOrEmpty(id))
                    {
                        clb.ID = int.Parse(id);
                        clb_bl.Update(clb);
                    }
                    else
                    {
                        clb.CreateDate = DateTime.Now;
                        clb_bl.Add(clb);
                    }
                    Response.Write(Common.JSONHelper.ObjectToJSON(new { succ = true, id = clb.ID }));
                    break;
                
                case "clb_get":
                    clb_bl = new Com.Ooohd.Bll.Leader.ZS_Celebrity();
                    clb = clb_bl.GetSingle(int.Parse(Request["id"]));
                    clb.Name += "^" + clb.VisitedDate.ToString();
                    Response.Write(Common.JSONHelper.ObjectToJSON(clb));
                    break;
                case "clb_del":
                    clb_bl = new Com.Ooohd.Bll.Leader.ZS_Celebrity();
                    clb_bl.Delete(Request["ids"]);
                    Response.Write(Common.JSONHelper.ObjectToJSON(new { succ = true }));
                    break;
            }
        }
    }
}